package br.mikhas.lab.lang.tables;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public abstract class IndexedTable<T> {
	private ArrayList<T> list = new ArrayList<T>();
	private Set<T> set = new HashSet<T>();

	public int get(T item) {
		if (set.contains(item)) {
			return list.indexOf(item);
		} else {
			int size = list.size();
			list.add(item);
			set.add(item);
			return size;
		}
	}

	public T get(int index) {
		return list.get(index);
	}

	public List<T> getAll() {
		return Collections.unmodifiableList(list);
	}
}
